/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package renderer;

import java.awt.Component;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import main.MainFrame;
import panels.PersonPanel;
import obj.Page;
import obj.Person;
import util.PersonRequested;

/**
 *
 * @author jm1156
 */
public class PersonListRenderer extends JLabel implements ListCellRenderer {

    private PersonPanel informationPanel;

    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
        if (isSelected) {
            setBackground(list.getSelectionBackground());
            setForeground(list.getSelectionForeground());
        } else {
            setBackground(list.getBackground());
            setForeground(list.getForeground());
        }

        informationPanel = new PersonPanel((Person) value);
        if (cellHasFocus) {
            PersonRequested personRequested = PersonRequested.getInstance();
            personRequested.setPerson((Person)value);
            MainFrame mainFrame = MainFrame.getInstance();
            Page page = new Page();
            page.setTitle("Dashboard");
            mainFrame.setPanel(page);
        }


        return informationPanel;
    }
}

